const { exec, execSync, spawn } = require('child_process');

// const timeoutP = () =>
//   new Promise((resolve, reject) => {
//     setTimeout(() => {
//       global.log.fail('Install yh-design TIMEOUT!');
//       global.log.fail('Please switch your proxy to t2');
//       reject(new Error());
//     }, 240000);
//   });

function makeProcess(command, args = []) {
  const p = new Promise((resolve, reject) => {
    const child = spawn(command, args, { stdio: 'inherit' });

    child.on('exit', () => {
      resolve(1);
    });

    child.on('close', () => {
      reject(new Error());
    });

    child.on('error', (err) => {
      reject(err);
    });
  });

  return p;

  // return Promise.race([timeoutP(), p]);
}

module.exports = makeProcess;
